#pragma once
#include <stdexcept>

class BitBuffer
{
	public:
		BitBuffer(void);
		BitBuffer(unsigned int size, unsigned int symbolSize = 8);
		BitBuffer(unsigned char* buffer, unsigned int size, unsigned int numberOfBits, unsigned int symbolSize = 8);
		BitBuffer(const BitBuffer& buffer);
		virtual ~BitBuffer(void);
		void appendBit(unsigned char bit);
		unsigned char popBit();
		void getBits(BitBuffer *bufferToPlaceBits, int firstBitIndex, int bitCount);
		unsigned char getBit(int index);
		void setBit(unsigned char bit, int index);
		//static unsigned char * getMaskForBitsNumber(int firstBitIndex, int bitCount, int byteCount);
		void printBuffer();
		unsigned char* getBuffer();
		int getSize();
		void resetPointers();
		bool hasBits();
		unsigned int numberOfBits();
		
		unsigned int popSymbol();
		void pushSymbol(unsigned int symbol);

		BitBuffer& operator=(const BitBuffer& buffer);
	private:
		unsigned char* buffer;
		unsigned int size;
		unsigned int symbolSize;
		unsigned int currentByte;
		unsigned char bitMask;
		unsigned int bitsPushed;

	public:
		class CurrentBitExceedsBytes : public std::runtime_error
		{
		public:
			CurrentBitExceedsBytes():runtime_error("Current bit is out of range of assigned bytes!"){}
			~CurrentBitExceedsBytes(){}
		};
			

};

